<template>
  <div class="tab-bar-item" @click="itemClick">
    <div v-if="!active">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-icon-active"></slot>
    </div>
    <div :style="activeStyle">
      <slot name="item-text"></slot>
    </div>
    <!-- <img src="../../assets/img/tabbar/_home.png" alt="">
     <div>首页</div>-->
  </div>
</template>

<script>

export default {
  name: "TabBarItem",
  data() {
    return {
      isActive: false,
    }

  },
  props: {
    path: {
      type: String,
      default: '/'
    },
    activeColor: {
      type: String,
      default: 'red'
    }
  },
  methods: {
    itemClick() {
      console.log(this.path)
      this.$router.push(this.path)
        /*this.isActive =(this.$route.path.indexOf(this.path) !== -1);
      console.log(this.$route.path.indexOf(this.path), this.isActive)

      console.log(this.$route.path)*/

    }
  },
  computed: {
    active() {
      this.isActive = this.$route.path.indexOf(this.path) !== -1
      return this.isActive
    },
    activeStyle() {
      return this.isActive ? {color: this.activeColor} : {}
    }
  }
}
</script>

<style scoped>
.tab-bar-item img {
  width: 24px;
  height: 24px;
  vertical-align: middle;
  margin: 3px 0;

}

.tab-bar-item {
  flex: 1;
  height: 49px;
  text-align: center;
  font-size: 12px;

}


</style>